package com.dcms.power.service.impl;

import com.dcms.power.bean.Menu;
import com.dcms.power.dao.MenuMapper;
import com.dcms.power.service.IMenuService;
import com.dcms.util.ClassUtil;
import com.dcms.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * \*
 * \* @name: MenuServiceImpl
 * \* @author: 武佳伟丶
 * \* @date: 2018/4/8 0008
 * \* @time: 19:20
 * \* @description: To change this template use File | Settings | File Templates.
 * \
 */
@Service
public class MenuServiceImpl implements IMenuService{

    @Autowired
    private MenuMapper mapper;

    @Override
    public int deleteByPrimaryKey(Integer roleId) {
        return mapper.deleteByPrimaryKey(roleId);
    }

    @Override
    public int insertSelective(Menu record) {
        return mapper.insertSelective(record);
    }

    @Override
    public Menu selectByPrimaryKey(Integer roleId) {
        return mapper.selectByPrimaryKey(roleId);
    }

    @Override
    public int updateByPrimaryKeySelective(Menu record) {
        return mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public List<Menu> selectAll(String param, Menu record) {
        Map map = new HashMap();
        if (StringUtil.isNotEmpty(param)){
            map.put("param", StringUtil.appendPerCent(param));
        }
        map.putAll(ClassUtil.getFields(record, false));
        return mapper.selectAll(map);
    }

    @Override
    public List<Menu> selectMenuByItemId(Integer userId, Integer roleId){
        Map map = new HashMap();
        if (userId != null){
            map.put("userId", userId);
        }
        if (roleId != null){
            map.put("roleId", roleId);
        }
        return mapper.selectMenuByUserId(map);
    }

    @Override
    public int deleteByPid(Integer pid) {
        return mapper.deleteByPid(pid);
    }

}